import sys

sys.path.append("..")  # 也可以这样sys.path.append("../..")
from api.modelsItem.SlideItem import AudioWithImages, SlideItem
from fastapi import APIRouter
from Plugin.图片合成幻灯片 import 图片合成幻灯片, 图片幻灯片V2
from concurrent.futures import ThreadPoolExecutor


slide_api = APIRouter()
executor = ThreadPoolExecutor(max_workers=10)  # 有10个线程池,那么能在这里阻塞

@slide_api.post("/images")
async def slideV1(item: SlideItem, summary="传入照片合成视频"):
    import time
    start = time.time()
    transition_effect = item.transition_effect
    transition_duration = item.transition_duration
    audio_path = item.audio_path
    images_paths_urls = item.images_paths_urls
    all_res_url = 图片合成幻灯片.start(audio_path, images_paths_urls, transition_effect, transition_duration)

    res_url = all_res_url.split("aliyuncs.com/")[-1]

    return {"res_url": res_url, "all_url": all_res_url, "duration": time.time() - start, "error_message": ""}


@slide_api.post("/imagesV2")
async def slideV2(item: AudioWithImages, summary="传入照片合成视频,可以更加定制化"):
    import time
    start = time.time()
    all_res_url = 图片幻灯片V2.main(item.image_list_data, item.audio_url)
    res_url = all_res_url.split("aliyuncs.com/")[-1]

    return {"res_url": res_url, "all_url": all_res_url, "duration": time.time() - start, "error_message": ""}
